
extern "C" {
    pub type args;
    pub type cmd;
    pub type cmdq_item;
    fn free(_: *mut ());
    fn args_get(_: *mut args, _: u_char) -> *const i8;
    fn cmd_get_entry(_: *mut cmd) -> *const cmd_entry;
    fn cmd_get_args(_: *mut cmd) -> *mut args;
    fn cmdq_print(_: *mut cmdq_item, _: *const i8, _: ...);
    fn cmdq_error(_: *mut cmdq_item, _: *const i8, _: ...);
    static mut status_prompt_hlist: [*mut *mut i8; 0];
    static mut status_prompt_hsize: [u_int; 0];
    fn status_prompt_type_string(_: u_int) -> *const i8;
    fn status_prompt_type(type_0: *const i8) -> prompt_type;
}
pub type __u_char = u8;
pub type __u_int = u32;
pub type u_char = __u_char;
pub type u_int = __u_int;
pub type prompt_type = u32;
pub const PROMPT_TYPE_INVALID: prompt_type = 255;
pub const PROMPT_TYPE_WINDOW_TARGET: prompt_type = 3;
pub const PROMPT_TYPE_TARGET: prompt_type = 2;
pub const PROMPT_TYPE_SEARCH: prompt_type = 1;
pub const PROMPT_TYPE_COMMAND: prompt_type = 0;
pub type args_parse_type = u32;
pub const ARGS_PARSE_COMMANDS: args_parse_type = 3;
pub const ARGS_PARSE_COMMANDS_OR_STRING: args_parse_type = 2;
pub const ARGS_PARSE_STRING: args_parse_type = 1;
pub const ARGS_PARSE_INVALID: args_parse_type = 0;
pub type args_parse_cb =
    Option<unsafe extern "C" fn(*mut args, u_int, *mut *mut i8) -> args_parse_type>;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct args_parse {
    pub template: *const i8,
    pub lower: i32,
    pub upper: i32,
    pub cb: args_parse_cb,
}
pub type cmd_find_type = u32;
pub const CMD_FIND_SESSION: cmd_find_type = 2;
pub const CMD_FIND_WINDOW: cmd_find_type = 1;
pub const CMD_FIND_PANE: cmd_find_type = 0;
pub type cmd_retval = i32;
pub const CMD_RETURN_STOP: cmd_retval = 2;
pub const CMD_RETURN_WAIT: cmd_retval = 1;
pub const CMD_RETURN_NORMAL: cmd_retval = 0;
pub const CMD_RETURN_ERROR: cmd_retval = -1;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct cmd_entry_flag {
    pub flag: i8,
    pub type_0: cmd_find_type,
    pub flags: i32,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct cmd_entry {
    pub name: *const i8,
    pub alias: *const i8,
    pub args: args_parse,
    pub usage: *const i8,
    pub source: cmd_entry_flag,
    pub target: cmd_entry_flag,
    pub flags: i32,
    pub exec: Option<unsafe extern "C" fn(*mut cmd, *mut cmdq_item) -> cmd_retval>,
}
#[no_mangle]
pub static mut cmd_show_prompt_history_entry: cmd_entry = {
    {
        let mut init = cmd_entry {
            name: b"show-prompt-history\0" as *const u8 as *const i8,
            alias: b"showphist\0" as *const u8 as *const i8,
            args: {
                let mut init = args_parse {
                    template: b"T:\0" as *const u8 as *const i8,
                    lower: 0,
                    upper: 0,
                    cb: None,
                };
                init
            },
            usage: b"[-T type]\0" as *const u8 as *const i8,
            source: cmd_entry_flag {
                flag: 0,
                type_0: CMD_FIND_PANE,
                flags: 0,
            },
            target: cmd_entry_flag {
                flag: 0,
                type_0: CMD_FIND_PANE,
                flags: 0,
            },
            flags: 0x4 as i32,
            exec: Some(
                cmd_show_prompt_history_exec
                    as unsafe extern "C" fn(*mut cmd, *mut cmdq_item) -> cmd_retval,
            ),
        };
        init
    }
};
#[no_mangle]
pub static mut cmd_clear_prompt_history_entry: cmd_entry = {
    {
        let mut init = cmd_entry {
            name: b"clear-prompt-history\0" as *const u8 as *const i8,
            alias: b"clearphist\0" as *const u8 as *const i8,
            args: {
                let mut init = args_parse {
                    template: b"T:\0" as *const u8 as *const i8,
                    lower: 0,
                    upper: 0,
                    cb: None,
                };
                init
            },
            usage: b"[-T type]\0" as *const u8 as *const i8,
            source: cmd_entry_flag {
                flag: 0,
                type_0: CMD_FIND_PANE,
                flags: 0,
            },
            target: cmd_entry_flag {
                flag: 0,
                type_0: CMD_FIND_PANE,
                flags: 0,
            },
            flags: 0x4 as i32,
            exec: Some(
                cmd_show_prompt_history_exec
                    as unsafe extern "C" fn(*mut cmd, *mut cmdq_item) -> cmd_retval,
            ),
        };
        init
    }
};
extern "C" fn cmd_show_prompt_history_exec(
    mut self_0: *mut cmd,
    mut item: *mut cmdq_item,
) -> cmd_retval {
    let mut args: *mut args = unsafe { cmd_get_args(self_0) };
    let mut typestr: *const i8 = unsafe { args_get(args, 'T' as i32 as u_char) };
    let mut type_0: prompt_type = PROMPT_TYPE_COMMAND;
    let mut tidx: u_int = 0;
    let mut hidx: u_int = 0;
    if (unsafe { cmd_get_entry(self_0) })
        == (unsafe { &cmd_clear_prompt_history_entry }) as *const cmd_entry
    {
        if typestr.is_null() {
            tidx = 0 as u_int;
            while tidx < 4 as u32 {
                (unsafe {
                    free(*status_prompt_hlist.as_mut_ptr().offset(tidx as isize)
                        as *mut ())
                });
                let fresh0 =
                    unsafe { &mut (*status_prompt_hlist.as_mut_ptr().offset(tidx as isize)) };
                *fresh0 = std::ptr::null_mut::<*mut i8>();
                (unsafe {
                    *status_prompt_hsize.as_mut_ptr().offset(tidx as isize) = 0 as u_int
                });
                tidx = tidx.wrapping_add(1);
            }
        } else {
            type_0 = unsafe { status_prompt_type(typestr) };
            if type_0 as u32 == PROMPT_TYPE_INVALID as i32 as u32 {
                (unsafe {
                    cmdq_error(
                        item,
                        b"invalid type: %s\0" as *const u8 as *const i8,
                        typestr,
                    )
                });
                return CMD_RETURN_ERROR;
            }
            (unsafe {
                free(*status_prompt_hlist.as_mut_ptr().offset(type_0 as isize) as *mut ())
            });
            let fresh1 =
                unsafe { &mut (*status_prompt_hlist.as_mut_ptr().offset(type_0 as isize)) };
            *fresh1 = std::ptr::null_mut::<*mut i8>();
            (unsafe {
                *status_prompt_hsize.as_mut_ptr().offset(type_0 as isize) = 0 as u_int
            });
        }
        return CMD_RETURN_NORMAL;
    }
    if typestr.is_null() {
        tidx = 0 as u_int;
        while tidx < 4 as u32 {
            (unsafe {
                cmdq_print(
                    item,
                    b"History for %s:\n\0" as *const u8 as *const i8,
                    status_prompt_type_string(tidx),
                )
            });
            hidx = 0 as u_int;
            while hidx < (unsafe { *status_prompt_hsize.as_mut_ptr().offset(tidx as isize) }) {
                (unsafe {
                    cmdq_print(
                        item,
                        b"%d: %s\0" as *const u8 as *const i8,
                        hidx.wrapping_add(1 as i32 as u32),
                        *(*status_prompt_hlist.as_mut_ptr().offset(tidx as isize))
                            .offset(hidx as isize),
                    )
                });
                hidx = hidx.wrapping_add(1);
            }
            (unsafe {
                cmdq_print(
                    item,
                    b"%s\0" as *const u8 as *const i8,
                    b"\0" as *const u8 as *const i8,
                )
            });
            tidx = tidx.wrapping_add(1);
        }
    } else {
        type_0 = unsafe { status_prompt_type(typestr) };
        if type_0 as u32 == PROMPT_TYPE_INVALID as i32 as u32 {
            (unsafe {
                cmdq_error(
                    item,
                    b"invalid type: %s\0" as *const u8 as *const i8,
                    typestr,
                )
            });
            return CMD_RETURN_ERROR;
        }
        (unsafe {
            cmdq_print(
                item,
                b"History for %s:\n\0" as *const u8 as *const i8,
                status_prompt_type_string(type_0 as u_int),
            )
        });
        hidx = 0 as u_int;
        while hidx < (unsafe { *status_prompt_hsize.as_mut_ptr().offset(type_0 as isize) }) {
            (unsafe {
                cmdq_print(
                    item,
                    b"%d: %s\0" as *const u8 as *const i8,
                    hidx.wrapping_add(1 as i32 as u32),
                    *(*status_prompt_hlist.as_mut_ptr().offset(type_0 as isize))
                        .offset(hidx as isize),
                )
            });
            hidx = hidx.wrapping_add(1);
        }
        (unsafe {
            cmdq_print(
                item,
                b"%s\0" as *const u8 as *const i8,
                b"\0" as *const u8 as *const i8,
            )
        });
    }
    return CMD_RETURN_NORMAL;
}
